package com.sjb.sixteen_journey_backend.controller;


import com.sjb.sixteen_journey_backend.common.R;
import com.sjb.sixteen_journey_backend.entity.AirTicket;
import com.sjb.sixteen_journey_backend.service.IAirTicketService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * 机票晒单表
 *
 * @author jcz
 * @since 2024-07-13
 */
@RestController
@RequestMapping("/air-ticket")
public class AirTicketController {
    @Autowired
    private IAirTicketService airTicketService;

    /**
     * 增加机票晒单
     * @param airTicket
     * @return
     */
    @PostMapping("/addAirTicketOss")
    public R addAirTicket(@RequestBody @Valid AirTicket airTicket) {
        return airTicketService.addAirTicket(airTicket);
    }

//    @PostMapping("/addAirTicket")
//    public R addAirTicket(@RequestBody AirTicket airTicket, @RequestParam("image") ArrayList<MultipartFile> images) {
//        return airTicketService.addAirTicket(airTicket, images);
//    }

    /**
     * 删除用户的一篇机票晒单
     * @param id
     * @return
     */
    @DeleteMapping("/deleteAirTicketById/{id}")
    public R deleteAirTicketById(@PathVariable("id") Integer id ) {
        return airTicketService.deleteAirTicketById(id);
    }

    /**
     * 获取所有机票晒单
     * @return
     */
    @GetMapping("showAllAirTicket")
    public R<List<AirTicket>> showAllAirTicket(){
        return airTicketService.showAllAirTicket();
    }

    /**
     * 根据晒单id查机票晒单
     * @param id 晒单id
     * @return
     */
    @GetMapping("showAllAirTicketById/{id}")
    public R showAllAirTicketById(@PathVariable("id") Integer id){
        return airTicketService.showAllAirTicketById(id,true);
    }


    /**
     * 根据用户id获取所有机票晒单
     * @return
     */
    @GetMapping("showAllAirTicketByUserId")
    public  R<List<AirTicket>> showAllAirTicketByUserId(){
        return airTicketService.showAllAirTicketByUserId();
    }

    /**
     * 相关机票晒单
     * @return
     */
    @GetMapping("getOtherAirTicket")
    public  R<List<AirTicket>> getOtherAirTicket(@RequestParam String originCity, @RequestParam String arriveCity){
        return airTicketService.getOtherAirTicket(originCity, arriveCity);
    }

}
